<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>生态瞬时评估 - 主页</title>

    <meta name="keywords" content="">
    <meta name="description" content="">

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="shortcut icon" href="../favicon.ico">
    <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="../css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body>
<div class="wrapper wrapper-content animated fadeInRight">
    <!--<div class="row">-->
        <!--<div class="col-sm-3 col-sm-offset-9"><a class="btn btn-primary">详情</a></div>-->
    <!--</div>-->
    <div class="row">
        <h3 class="col-sm-offset-3 col-sm-6 text-center">新建答题策略</h3>
    </div>
    <div class="row">
        <div class="col-sm-offset-3 col-sm-6">
            <form class="form-horizontal" style="margin-top: 20px">
                <div class="form-group">
                    <label for="strategy-name" class="col-sm-3 control-label">策略名称：</label>
                    <div class="col-sm-8">
                        <input type="text" placeholder="请输入策略名称" class="form-control" id="strategy-name">
                    </div>
                </div>



                <div class="form-group">
                    <label for="start-time" class="col-sm-3 control-label">开始时间：</label>
                    <div class="col-sm-8">
                        <input type="text" class="laydate-icon form-control layer-date" id="start-time" placeholder="输入开始时间（例如13:30）">
                    </div>
                </div>

                <div class="form-group">
                    <label for="end-time" class="col-sm-3 control-label">结束时间：</label>
                    <div class="col-sm-8">
                        <input type="text" class="laydate-icon form-control layer-date" id="end-time" placeholder="输入结束时间（例如13:30）">
                    </div>
                </div>

                <div class="form-group">
                    <label for="frequency" class="col-sm-3 control-label">答题频率：</label>
                    <div class="col-sm-8">
                        <input type="text" placeholder="请输入答题频率" class="form-control" id="frequency">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">类型：</label>
                    <div class="col-sm-8" id="Stype">
                        <div class="radio-inline i-checks">
                            <label>
                                <input type="radio" value="0" name="answer-type"> <i></i> 固定</label>
                        </div>
                        <div class="radio-inline i-checks">
                            <label>
                                <input type="radio" value="1" name="answer-type"> <i></i> 随机</label>
                        </div>
                    </div>
                </div>
                <div class="col-sm-offset-3 col-sm-8">
                    <input type="button" id="addBtn" value="确认" class="btn btn-primary btn-block">
                </div>
            </form>
        </div>
    </div>

</div>




<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/bootstrap.min.js?v=3.3.6"></script>
<script src="../js/dateChange.js"></script>
<script src="../js/plugins/layer/laydate/laydate.js"></script>
<!--icheck-->
<script src="../js/plugins/iCheck/icheck.min.js"></script>
<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });

    });
</script>
<script>
    var testId = sessionStorage.getItem("testId");
    var token = sessionStorage.getItem("token");
    var reg = /^[0|1|2]{1}[0-9]{1}:[0-9]{1,2}$/;
    $("#addBtn").click(function () {
        var date = new Date();
        var beginTime="";
        var endTime = "";
        if(reg.test($("#start-time").val())&&reg.test($("#end-time").val())){
            beginTime = $("#start-time").val().trim();

            endTime = $("#end-time").val().trim();
            console.log(endTime,beginTime);
        }else{
            alert("开始时间或接受时间格式不正确，请重新输入！");
            return;
        }

        var btimes = beginTime.split(":");
        var etimes = endTime.split(":");
        var $beginT = new Date().setHours(btimes[0],btimes[1],0);
        var $endT = new Date().setHours(etimes[0],etimes[1],0);
        var $strategyName = $("#strategy-name").val();
        var $rate = $("#frequency").val();
        var $type = $("#Stype .checked").find("input").val()==0?"FIXED":"RANDOM";
        var _data = JSON.stringify({"experimentId":testId,"name":$strategyName,"beginTime":$beginT,"endTime":$endT,"offsetTime":10, "rate":$rate, "type":$type});
        console.info(_data);
        if($strategyName == " "||$beginT == " "||$endT == " "||$rate == ""||$type == ""){
            alert("请填写所有信息！");
        }else{
            $.ajax({
                type:"POST",
                url:"http://123.206.18.189:8080/experiments/"+testId+"/examination_strategy",
                headers:{
                    authToken:token
                },
                contentType:"application/json",
                data:_data,
                complete:function (XMLHttpResquest) {
                    if(XMLHttpResquest.status == 200&& XMLHttpResquest.readyState == 4){
                        alert("答题策略添加成功！");
                        window.history.back();
                    }
                    
                }

            })
        }
    })
</script>
</body>
</html>